package besta.moon.sql.expression.function;

import besta.moon.sql.datatype.MutableNumeric;
import besta.moon.sql.parser.SQLTokenizer;
import besta.moon.util.MoonUtils;

public abstract class FunctionReturnInt extends ExpressionFunction {

    @Override
    public boolean isNull() throws Exception {
        return param1.isNull();
    }

    @Override
    public final boolean getBoolean() throws Exception {
        return getInt() != 0;
    }

    @Override
    public final long getLong() throws Exception {
        return getInt();
    }

    @Override
    public final float getFloat() throws Exception {
        return getInt();
    }

    @Override
    public final double getDouble() throws Exception {
        return getInt();
    }

    @Override
    public final long getMoney() throws Exception {
        return getInt() * 10000;
    }

    @Override
    public final MutableNumeric getNumeric() throws Exception {
        if (isNull()) {
            return null;
        }
        return new MutableNumeric(getInt());
    }

    @Override
    public Object getObject() throws Exception {
        if (isNull()) {
            return null;
        }
        return MoonUtils.getInteger(getInt());
    }

    @Override
    public final String getString() throws Exception {
        if (isNull()) {
            return null;
        }
        return String.valueOf(getInt());
    }

    @Override
    public final int getDataType() {
        return SQLTokenizer.INT;
    }

}
